﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DreametryMIS
{
    public static class promptTaskDestails
    {
        public static string ShowDialog(string name, String nick)
        {
            Form prompt = new Form()
            {
                Width = 325,
                Height = 480,
                FormBorderStyle = FormBorderStyle.Sizable,
                BackColor = System.Drawing.Color.White,
                Text = "Task Details",
                Font = new Font("Segoe UI", 10, FontStyle.Regular),
                StartPosition = FormStartPosition.CenterScreen,
                MaximizeBox = false,
                MinimizeBox = false
            };
            Button confirmation = new Button() { Text = "Go to codiga", Left = 155, Width = 150,Height=30, Top = 410, FlatStyle = FlatStyle.Flat, Cursor = Cursors.Hand, Dock = DockStyle.Bottom };
            confirmation.FlatAppearance.BorderSize = 0;

            

            ListBox txtList = new ListBox()
            {
                SelectionMode = SelectionMode.One,
                Visible = true,
                Left = 10,
                Top = 10,
                Width = 300,
                Height = 400,
                BorderStyle = BorderStyle.None,
                BackColor = Color.White,
                Dock = DockStyle.Fill
            };
            
            confirmation.Click += (sender, e) => {
                
                try
                {
                    txtList.SelectedIndex = 0;
                    System.Diagnostics.Process.Start(txtList.GetItemText(txtList.SelectedItem));
                    //string s1 = "";
                    //foreach (object item in txtList.SelectedItems) s1 += item.ToString() + "\r\n"; Clipboard.SetText(s1);
                    //MessageBox.Show("Selected items copied", "Copy", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch {
                    MessageBox.Show("Selected text isn't a link", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            };


            var fileStream = new FileStream(@"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\"+nick+@"\logs\"+ name + ".txt", FileMode.Open, FileAccess.Read);
            using (var streamReader = new StreamReader(fileStream, Encoding.Default))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    txtList.Items.Add(line);
                }
            }


            prompt.Controls.Add(txtList);
            prompt.Controls.Add(confirmation);
            prompt.AcceptButton = confirmation;

            return prompt.ShowDialog() == DialogResult.OK ? "" : "";
        }
    }
}
